#pragma once

#include "./base_type.h"

namespace lukv {


class string_t : public base_type {
public:
    string_t();
    string_t(const string_t &);
    string_t(string_t &&) noexcept;
    explicit string_t(std::string);
public:
    ~string_t() noexcept override;
public:
    data_type get_type() override;
    std::pair<char, std::string> handle(const std::vector<std::string> &) override;
public:
    void set(std::string);
    std::string get();
private:
    std::string _content;
};


string_t::string_t() = default;

string_t::string_t(const string_t & _str) {
    _content = _str._content;
}

string_t::string_t(string_t && _str) noexcept {
    _content = std::move(_str._content);
}

string_t::string_t(std::string _s) {
    _content = std::move(_s);
}

string_t::~string_t() noexcept = default;

data_type string_t::get_type() {
    return string;
}

std::pair<char, std::string> string_t::handle(const std::vector<std::string> & _cmds) {
    if (_cmds[0] != "string") {
        LOG_ERR(ERR_TYPE);
        return { -1, ERR_TYPE };
    }
    if (_cmds[1] == "get") return { 0, get() };
    else if (_cmds[1] == "set") set(_cmds.size() > 3 ? _cmds[3] : "");
    else {
        LOG_ERR(ERR_OPT);
        return { -1, ERR_OPT };
    }
    return { 0, OPT_SUCC };
}

void string_t::set(std::string _str) {
    _content = std::move(_str);
}

std::string string_t::get() {
    return _content;
}

}

